package com.tywj.panda.customer.common.widget.recyclerview

import androidx.annotation.LayoutRes
import androidx.annotation.Nullable
import androidx.lifecycle.LifecycleOwner
import com.tywj.lib.core.widget.recycleview.adapter.BaseAdapter
import com.tywj.lib.lifecycle.livedata.ArrayListLiveData
import com.tywj.lib.lifecycle.livedata.ListChangedObserver

/**
 * @desc 基类RecyclerView适配器
 * @author TaylorZhang
 * @date 2018/5/8
 */
open class MyBaseAdapter<T> : BaseAdapter<T> {

    constructor() : super(0, null)

    constructor(@LayoutRes layoutResId: Int) : super(layoutResId, null)

    constructor(@Nullable data: List<T>) : super(0, data)

    constructor(@LayoutRes layoutResId: Int, @Nullable data: List<T>) : super(layoutResId, data)

    fun setArrayListLiveData(lifecycleOwner: LifecycleOwner, liveData: ArrayListLiveData<T>) {
        setNewData(liveData.rawList)

        ListChangedObserver(lifecycleOwner, this, liveData)
    }
}